<?php
class advice_model extends CI_Model {
	
	function __construct ()
	{
		parent::__construct();	
	}

	function count_advice_list()
	{
		$this->db->where('active',1);
		$query = $this->db->get('advice');
		return $query->num_rows();	
	}

	function get_advice_list($num = 10, $offset = 0)
	{
		$this->db->where('active',1);	
		$this->db->order_by('subject_vn');
		$query = $this->db->get('advice',$num, $offset);
		return $query->result();	
	}
	
	function save()
	{
		$id = (int)$this->uri->segment(3);			
		$data = array(
			'subject_vn' => (string)$this->input->post('subject_vn'),
			'subject_us' => strtolower(stringchange($this->input->post('subject_vn'))),
			'content_small' => (string)$this->input->post('subcontent_vn'),
			'content_vn' => (string)$this->input->post('content_vn'),
			'active' => (int)$this->input->post('status'),
		);
		
		if($id!=0){
			  $this->db->where('tv_id',$id);
			  if($this->db->update('advice',$data)){
				  return true;
			  }else{
				  return false;
			  }
		}else{
			  if($this->db->insert('advice',$data)){
				  return true;
			  }else{
				  return false;
			  }
		}
	}

	function get_advice($id)
	{
		$this->db->where('tv_id',$id);
		$query = $this->db->get('advice');
		return $query->row();	
	}

	function delete($id)
	{
		$data = array('active' => -1);
		$this->db->where('tv_id',$id);
		if($this->db->update('advice', $data)){
		  return true;
		}else{
		  return false;
		}
	}

      function delsabout($id)
	  {
          $this->db->where('tv_id',$id);             
		  if($this->db->delete('advice')){
			  return true;
		  }else{
			  return false;
		  }
      }
}
?>